// pages/storyShowPage/storyShowPage.js
import room4TestData from "../testData/testR4Data";
import bottomEnterTestData from "../testData/testBottomEnterData";
var mfApi = require('../../api/api.js');
const app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        baseUrl: app.globalData.baseUrl,
        localRoomData: room4TestData,
        bottomEnterData: bottomEnterTestData,
        externalStoryId: null,

        isShotTip: false,
        tipBtnImage: '',
        tipContentImage: '',

        // 返回键
        top: 0,
        h: 0, //胶囊高度
    },

    onShareTimeline:function(){ 
 
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        console.log(options)
        if (options && options.storyId) {
            this.setData({
                externalStoryId: options.storyId,
            })
        }

        this.setData({
            // externalStoryId: "1518264171971973121",
            top: app.menu.top,
            h: app.menu.height
        })
    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        this.checkUser();
    },

    async checkUser() {
        let res = await mfApi.http(
            mfApi.getRoomList(app.globalData.openId), "GET", {});
        if (res.code != 200)
            return;


        let tempEnterData = this.data.bottomEnterData;
        tempEnterData.forEach(element => {
            // element.index
            let roomInfo = res.result.roomList.find(e => {
                return e.roomNo == element.enterIndex;
            });
            if (roomInfo)
                element.unlockFlag = roomInfo.unlockFlag;
        })

        this.setData({
            bottomEnterData: tempEnterData
        })
    },

    onStartClick() {
        app.globalData.indexTurnDoor = 1;
        this.setData({
            isShotTip: false
        })

        wx.navigateBack({
            delta: 1,
        })
    },

    /**
     * 底部入口点击
     */
    onBottomEnterClick(e) {
        let tempData = this.data.bottomEnterData.find(element => {
            return element.enterIndex == e.detail
        })

        // if (tempData.unlockFlag == "0") {
        //     this.setData({
        //         isShotTip: true,
        //         tipIsSmall: true,
        //         tipBtnImage: this.data.baseUrl + '/index/btn-explorer.png',
        //         tipContentImage: this.data.baseUrl + '/index/tip-lock-r5.png',
        //     })
        //     return;
        // }

        app.saveTrack(`storyShow - 去房间${e.detail}`);
        app.globalData.indexTurnDoor = e.detail;
        app.globalData.isFromShareDoor = true;
        wx.navigateBack({
            delta: 1,
        })
    },

    onTipBtnClick() {
        app.globalData.indexTurnDoor = 1;
        app.globalData.isFromShareDoor = true;
        this.setData({
            isShotTip: false
        })

        wx.navigateBack({
            delta: 1,
        })
    },

    onTipBtnCloseClick() {
        this.setData({
            isShotTip: false
        })
    },

    onBackClick() {
        wx.navigateBack({
            delta: 1,
        })
    },

    onShareAppMessage(object) {
        return {
            title: 'LA MER邀你一同参展，探寻属于你的自愈空间',
            path: `/pages/index/index?inChannel=commonShare`,
            imageUrl: "https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/2022_lamer_cream_show/share/wx-share.jpg",
        }
    }
})